module namespace page="http://sendmeafilter.com/common/page";

import module namespace header="http://sendmeafilter.com/common/header" at "header.xqy";
import module namespace footer="http://sendmeafilter.com/common/footer" at "footer.xqy";
import module namespace why="http://sendmeafilter.com/common/whychooseus" at "whychooseus.xqy";
import module namespace meta="http://sendmeafilter.com/common/meta" at "meta.xqy";
import module namespace terms="http://sendmeafilter.com/common/terms" at "terms.xqy";

declare boundary-space preserve;
declare option xdmp:mapping "false";

declare function page:page($meta, $content) {
(
	header:doctype(),
	<html lang="en"><!--<![endif]-->
		<head>
			<title>{page:option('title',$meta)}</title>
			{ meta:meta($meta) }
		</head> 
		<body id="index">
			{ terms:terms($meta) }
			{ header:header($meta) }
			<div id="main-body">	
					{ $content }
			</div>
			{ footer:footer($meta) }
			<div id="gray-box"></div><!-- Modal Gray Box -->
		</body>
	</html>
)
};

declare function page:info($title) {
	let $docname := fn:concat("/config",xdmp:get-original-url(),".xml")
	let $doc := fn:doc($docname)/xml/node()
(:	let $err := fn:error():)
	return 
	page:page (
		(
			page:meta('title', fn:concat($title,' - SendMeAFilter.com')),
			page:meta('description', fn:concat('About Us - SendMeAFilter.com'))
		),
	
		<div class="wrapper">
			<div class="page-style">
				{ page:prefer($doc,<p>blank</p>) }
			</div>
		</div>
	)
};

declare function page:data($type) {
	let $docname := fn:concat("/config",xdmp:get-original-url())
	let $doc := fn:doc($docname)//text()
	let $set := xdmp:set-response-content-type($type)
(:	let $doc := if(fn:contains($type,'javascript')) then fn:concat('(',$doc,')') else $doc:)
(:	let $e := fn:error():)
	return $doc
};


declare function page:prefer($one,$two) { if(fn:exists($one)) then $one else $two };
declare function page:option($name,$meta) { fn:data(($meta[@name=$name]/@value)[1]) }; 
declare function page:meta($name) { element meta { attribute name { $name }, attribute value {'true'} } }; 
declare function page:meta($name,$value) { element meta { attribute name { $name }, attribute value { $value } } }; 